<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>意见反馈 - 邦伴用户端</title>
  <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
  <style>
    :root {
      --primary: #ff7e2d;
      --primary-light: #fff3ea;
      --border: #f0f0f0;
      --text-main: #222;
      --text-sub: #888;
    }
    
    body {
      font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
      background-color: #f8f8f8;
      color: var(--text-main);
    }
    
    .app-container {
      width: 375px;
      height: 812px;
      margin: 0 auto;
      background: #fff;
      position: relative;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
      overflow-y: auto;
    }
    
    .primary-color {
      color: var(--primary);
    }
    
    .primary-bg {
      background-color: var(--primary);
    }
    
    .primary-light-bg {
      background-color: var(--primary-light);
    }
    
    .btn-primary {
      background-color: var(--primary);
      color: white;
    }
    
    .btn-outline {
      border: 1px solid var(--primary);
      color: var(--primary);
    }
    
    .form-textarea {
      width: 100%;
      padding: 12px;
      border: 1px solid var(--border);
      border-radius: 8px;
      font-size: 14px;
      resize: none;
      min-height: 150px;
    }
    
    .form-textarea:focus {
      outline: none;
      border-color: var(--primary);
    }
    
    .feedback-type {
      border: 1px solid #ddd;
      border-radius: 20px;
      padding: 6px 16px;
      font-size: 14px;
    }
    
    .feedback-type.active {
      background-color: var(--primary-light);
      border-color: var(--primary);
      color: var(--primary);
    }
    
    .image-upload {
      width: 80px;
      height: 80px;
      border: 1px dashed #ddd;
      border-radius: 8px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }
    
    .image-preview {
      width: 80px;
      height: 80px;
      border-radius: 8px;
      position: relative;
      overflow: hidden;
      margin-right: 10px;
    }
    
    .image-preview img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    
    .image-preview .delete-btn {
      position: absolute;
      top: -6px;
      right: -6px;
      width: 20px;
      height: 20px;
      background-color: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
    }
  </style>
</head>
<body>
  <div class="app-container">
    <!-- 顶部导航栏 -->
    <div class="sticky top-0 z-10 bg-white border-b border-gray-100 px-4 py-3 flex items-center">
      <a href="javascript:history.back()" class="mr-2">
        <i class="fas fa-arrow-left text-lg"></i>
      </a>
      <h1 class="text-lg font-medium flex-1 text-center">意见反馈</h1>
    </div>
    
    <!-- 反馈表单 -->
    <div class="p-4">
      <form id="feedbackForm">
        <!-- 反馈类型 -->
        <div class="mb-4">
          <h2 class="text-base font-medium mb-3">反馈类型</h2>
          <div class="flex flex-wrap gap-2">
            <button type="button" class="feedback-type active" data-type="bug">功能异常</button>
            <button type="button" class="feedback-type" data-type="suggestion">功能建议</button>
            <button type="button" class="feedback-type" data-type="complaint">投诉</button>
            <button type="button" class="feedback-type" data-type="other">其他</button>
          </div>
          <input type="hidden" id="feedbackType" name="feedbackType" value="bug">
        </div>
        
        <!-- 反馈内容 -->
        <div class="mb-4">
          <h2 class="text-base font-medium mb-3">反馈内容</h2>
          <textarea class="form-textarea" id="feedbackContent" name="feedbackContent" placeholder="请详细描述您遇到的问题或建议，有助于我们更好地解决问题..."></textarea>
          <p class="text-xs text-gray-400 mt-1 text-right"><span id="charCount">0</span>/500</p>
        </div>
        
        <!-- 上传图片 -->
        <div class="mb-6">
          <h2 class="text-base font-medium mb-3">上传图片（选填）</h2>
          <div class="flex items-center">
            <div id="imagePreviewContainer" class="flex mr-3">
              <!-- 预览图片将在这里显示 -->
            </div>
            <label for="imageUpload" class="image-upload">
              <i class="fas fa-camera text-gray-400 mb-1"></i>
              <span class="text-xs text-gray-400">添加图片</span>
            </label>
            <input type="file" id="imageUpload" name="images[]" accept="image/*" multiple class="hidden">
          </div>
          <p class="text-xs text-gray-400 mt-2">最多可上传3张图片，每张不超过5MB</p>
        </div>
        
        <!-- 联系方式 -->
        <div class="mb-6">
          <h2 class="text-base font-medium mb-3">联系方式（选填）</h2>
          <input type="text" class="w-full p-3 border border-gray-200 rounded-lg" placeholder="请留下您的手机号或邮箱，方便我们联系您" name="contact">
        </div>
        
        <!-- 提交按钮 -->
        <button type="submit" class="w-full py-3 btn-primary text-center rounded-lg">提交反馈</button>
      </form>
    </div>
    
    <!-- 提交成功弹窗 -->
    <div id="successModal" class="fixed inset-0 bg-black bg-opacity-50 hidden flex items-center justify-center z-50">
      <div class="bg-white rounded-lg w-72 overflow-hidden">
        <div class="p-6 text-center">
          <div class="w-16 h-16 rounded-full bg-green-100 flex items-center justify-center mx-auto mb-4">
            <i class="fas fa-check text-2xl text-green-500"></i>
          </div>
          <h3 class="font-medium mb-2">提交成功</h3>
          <p class="text-sm text-gray-500 mb-4">感谢您的反馈，我们会尽快处理</p>
          <button id="closeSuccess" class="w-full py-2 btn-primary rounded-lg">确定</button>
        </div>
      </div>
    </div>
  </div>

  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // 反馈类型选择
      const typeButtons = document.querySelectorAll('.feedback-type');
      const typeInput = document.getElementById('feedbackType');
      
      typeButtons.forEach(button => {
        button.addEventListener('click', function() {
          // 移除所有按钮的激活状态
          typeButtons.forEach(btn => {
            btn.classList.remove('active');
          });
          
          // 激活当前按钮
          this.classList.add('active');
          
          // 设置隐藏输入值
          typeInput.value = this.dataset.type;
        });
      });
      
      // 字数统计
      const feedbackContent = document.getElementById('feedbackContent');
      const charCount = document.getElementById('charCount');
      
      feedbackContent.addEventListener('input', function() {
        const count = this.value.length;
        charCount.textContent = count;
        
        // 超过字数限制时截断
        if (count > 500) {
          this.value = this.value.substring(0, 500);
          charCount.textContent = 500;
        }
      });
      
      // 图片上传预览
      const imageUpload = document.getElementById('imageUpload');
      const imagePreviewContainer = document.getElementById('imagePreviewContainer');
      let uploadedImages = [];
      
      imageUpload.addEventListener('change', function() {
        const files = this.files;
        
        // 检查是否超过最大数量
        if (uploadedImages.length + files.length > 3) {
          alert('最多只能上传3张图片');
          return;
        }
        
        // 处理每个选择的文件
        for (let i = 0; i < files.length; i++) {
          const file = files[i];
          
          // 检查文件类型
          if (!file.type.startsWith('image/')) {
            alert('请上传图片文件');
            continue;
          }
          
          // 检查文件大小
          if (file.size > 5 * 1024 * 1024) {
            alert('图片大小不能超过5MB');
            continue;
          }
          
          // 创建预览
          const reader = new FileReader();
          reader.onload = function(e) {
            const imageId = 'img_' + Date.now() + '_' + i;
            uploadedImages.push({
              id: imageId,
              file: file
            });
            
            const previewDiv = document.createElement('div');
            previewDiv.className = 'image-preview';
            previewDiv.dataset.id = imageId;
            previewDiv.innerHTML = `
              <img src="${e.target.result}" alt="预览图片">
              <div class="delete-btn">
                <i class="fas fa-times"></i>
              </div>
            `;
            
            // 添加删除事件
            const deleteBtn = previewDiv.querySelector('.delete-btn');
            deleteBtn.addEventListener('click', function() {
              // 从数组中移除
              uploadedImages = uploadedImages.filter(img => img.id !== imageId);
              // 从DOM中移除
              previewDiv.remove();
            });
            
            imagePreviewContainer.appendChild(previewDiv);
          };
          
          reader.readAsDataURL(file);
        }
        
        // 重置input，允许再次选择相同文件
        this.value = '';
      });
      
      // 表单提交
      const feedbackForm = document.getElementById('feedbackForm');
      const successModal = document.getElementById('successModal');
      const closeSuccess = document.getElementById('closeSuccess');
      
      feedbackForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        // 验证表单
        const content = feedbackContent.value.trim();
        if (!content) {
          alert('请填写反馈内容');
          return;
        }
        
        // 收集表单数据
        const formData = new FormData();
        formData.append('type', typeInput.value);
        formData.append('content', content);
        formData.append('contact', this.querySelector('input[name="contact"]').value);
        
        // 添加图片
        uploadedImages.forEach(img => {
          formData.append('images[]', img.file);
        });
        
        console.log('提交的反馈数据:', {
          type: typeInput.value,
          content: content,
          contact: this.querySelector('input[name="contact"]').value,
          imageCount: uploadedImages.length
        });
        
        // 这里可以添加AJAX请求来提交表单
        // 显示成功弹窗
        successModal.classList.remove('hidden');
        successModal.classList.add('flex');
      });
      
      // 关闭成功弹窗
      closeSuccess.addEventListener('click', function() {
        successModal.classList.add('hidden');
        successModal.classList.remove('flex');
        
        // 重置表单
        feedbackForm.reset();
        charCount.textContent = '0';
        
        // 清空图片预览
        imagePreviewContainer.innerHTML = '';
        uploadedImages = [];
        
        // 重置反馈类型
        typeButtons.forEach(btn => {
          btn.classList.remove('active');
        });
        typeButtons[0].classList.add('active');
        typeInput.value = 'bug';
        
        // 返回上一页
        setTimeout(() => {
          window.history.back();
        }, 300);
      });
      
      // 点击弹窗外部关闭
      successModal.addEventListener('click', function(e) {
        if (e.target === successModal) {
          closeSuccess.click();
        }
      });
    });
  </script>
</body>
</html> 